var { customersDao,
    getSalesToCustomersDao,
    delSalesToCustomersDao,
    getModifyCustomersDao,
    modifyCustomersDao,
    getCustomersDao,getCustomersAllId
} = require('../dao/modules/customersDao');

// -- ----------- 严晴---------- --

// 新增客户
module.exports.customersService = async (customers) => {
    // console.log('222', customers);
    var data = await customersDao(customers);
    if (data) {
        return {
            message: '新增成功！',
            code: 1
        };
    } else {
        return {
            message: '新增失败！',
            code: 0
        };
    };
};

//  获取销售员客户
module.exports.getSalesToCustomersService = async (data) => {
    // console.log('222', data);
    var result = await getSalesToCustomersDao(data);
    // console.log('222', result);
    if (result) {
        return {
            message: '获取成功！',
            code: 1,
            result
        };
    } else {
        return {
            message: '获取失败！',
            code: 0
        };
    };
};

//  删除销售员客户
module.exports.delSalesToCustomersService = async (_id) => {
    // console.log('222', data);
    var data = await delSalesToCustomersDao(_id);
    // console.log('222', data);
    if (data) {
        return {
            message: '删除成功！',
            code: 1,
            data
        };
    } else {
        return {
            message: '删除失败！',
            code: 0
        };
    };
};

//  获得修改销售员客户数据
module.exports.getModifyCustomersService = async (_id) => {
    // console.log('222', _id);
    var data = await getModifyCustomersDao(_id);
    // console.log('222', data);
    if (data) {
        return {
            message: '获取要修改的客户数据成功！',
            code: 1,
            data
        };
    } else {
        return {
            message: '获取要修改的客户数据失败！',
            code: 0
        };
    };
};

//  确认修改客户数据
module.exports.modifyCustomersService = async ({ _id, name, age, gender, phone }) => {
    var data = await modifyCustomersDao({ _id, name, age, gender, phone });
    // console.log('222', data);
    if (data) {
        return {
            message: '修改客户数据成功！',
            code: 1,
            data
        };
    } else {
        return {
            message: '修改客户数据失败！',
            code: 0
        };
    };
};



//  获取管理员页面客户
module.exports.getCustomersService = async (data) => {
    var data = await getCustomersDao(data);
    // console.log('222', result);
    if (data) {
        return {
            message: '获取成功！',
            code: 1,
            data
        };
    } else {
        return {
            message: '获取失败！',
            code: 0
        };
    };
};

// 获取所有客户
module.exports.getCustomersAllId = async (data) => {
    var result = await getCustomersAllId(data);
    if (result) {
        return {
            message: '获取成功！',
            code: 1,
            result
        };
    } else {
        return {
            message: '获取失败！',
            code: 0
        };
    };
};